In-depth analysis of Alamofire source code in iOS development, iosalamofire
The Alamofire source code version in today's blog is the latest3.4The version is used as an example. The previous Blog system detailed NSURLSession-related things. For more information, see "Detailed NSURLSession" to lay the foundation for this blog. AlamoFire further encapsulates NSURLSe
AlamoFire's Thoughts
This article is translated by CocoaChina -- BYB_1132 (Forum ID)
Original article: Thoughts On AlamoFire -- Swift's AFNetworking Implementation
HTTP protocol is synonymous with modern development. For experienced iOS developers, it is the basis of daily work to be familiar with and try to use these popular protocols.
Unexpectedly, there is no difference in iOS applications in this regard. Thousands of apps and engineers rely on the
I. Alamofire core Modules OverviewLet's take a holistic look at the Alamofire framework relationship and outline some of the core modules. Let's take a look at the file organization structure of Alamofire, and then give the relationships of the classes in these file organization structures. Therefore, in this part of the classification chart is indispensable. Non
Tips:This tutorial is based on Xcode 7.3, IOS 9.3, and Swift 2.2
Alamofire is a Swift-based HTTP network library for IOS and Mac OS. It provides an elegant interface on Apple's base Network library, simplifying many common network tasks.Alamofire provides chained request and response methods, JSON parameters and response serialization and authorization, and so on. In this tutorial, you will use Alamofire
Description and configuration of Alamofire
1, what is Alamofire
(1) The predecessor of Alamofire is afnetworking. Afnetworking is a popular third party HTTP network base on IOS and OS x.
(2) In fact afnetwork prefix AF is the abbreviation of Alamofire.
(3) After Swift's release, Afnetworking's aut
Alamofire is an HTTP network library written in Swift, developed by author Mattt of the former popular open source project Afnetworking, and can be used very simply for asynchronous network communication.To get the latest version of Alamofire, go to Https://github.com/Alamofire/Alamofire and click the Download ZIP butt
Installation and use of third-party network request library Alamofire in SwiftAlamofire is one of the more popular network request libraries in Swift: Https://github.com/Alamofire/Alamofire. Here we introduce the installation and use of this library.One, install package management tool CocoapodsAs the domestic easy to be wall, the speed is very slow, here we use
When I did the swift version of the waterfall stream demo "Swift UITableView Waterfall stream/nsurlconnection Asynchronous network Request", the use of the Nsurlconnection made the network asynchronous request, the image of the asynchronous loading using GCD do. In the use of the process, the network request part is not a problem, but in the image of the asynchronous loading, because the picture is not cached, so when sliding up and down, you need to constantly load the picture, so the user expe
Viii. using Alamofire for user authentication
1,alamofire supports the following certifications (authentication)
This article explains the use of Alamofire for HTTP Basic authentication.
Introduction to 2,HTTP Basic certification
(1) HTTP Basic authentication is a way to allow HTTP servers to make user IDs for Web browsers.(2) When a client to the HTTP server
In the application development process, the network request is often required, in the process of the network request, the general third-party network frame timeout time is longer than 15 seconds;So, how do we specify the time-out for the request?In Swift's world, the more famous network is Alamofire Githut address: Https://github.com/Alamofire/AlamofireThen, when using
Swift-Add Pure AlamofireIf you have a neat code and can't tolerate any extra stuff, keep looking down.1. Download alamofire (https://github.com/Alamofire/Alamofire)2. Unzip and open alamofire.xcworkspace3. Delete unnecessary content (depending on your needs)4. Remove extraneous content from the folder5. Create a test project Swift-alamofire6. Embed the Alamofir
First, manual Import1, official website download Alamofire2. Unzip the downloaded file into the top-level directory of the project3. Open Project Add Files4, select Project TARGETS > General > Embedded Binaries > + (ADD) complete. Note Select the corresponding framework, we choose Frameworkios here5, detect whether to add success, first detect the project deployment version, using Alamofire project Deployment target minimum of 8.0, and then run the fo
Xcode7.1 use Cocoapods to install the third-party network library under Alamofire--swiftThe alamofire previously searched online was version 1.3. So the installation to Xcode7.1 will be error, so the Alamofire3.1 version with Cocoapods installation. Convenient for everyone to use.Alamofire Swift afnetworking Network Framework CocoaPodsAs a result of the previous online search
Vi. use Alamofire for file upload
1,alamofire supports the following types of uploads:
FileDataStreamMultipartformdata
2, upload files using the file stream
Let FileURL = Nsbundle.mainbundle (). Urlforresource ("Hangge", Withextension: "Zip")Alamofire.upload (. POST, "http://www.hangge.com/upload.php", file:fileurl!)
Attached: Service-side code (upload.php)
/** PHP Receive stream files* @param String
Alamofire is the Swift language's HTTP Web Development Toolkit, which is powerful and supports a variety of HTTP method, JSON, file uploads, file downloads, and multiple authentication methods.Afnetworking's author of the new masterpiece, native Swfit language, can basically meet the development of network programming in Swift.The URL for GitHub is:Https://github.com/Alamofire/AlamofireThe URL for git clone
Seven, use Alamofire for file download
1, custom download File save directoryThe following code downloads the logo picture to the user's document directory (Documnets directory), and the filename is unchanged.
Alamofire.download (. Get, "Yun_qi_img/logo.png") {Temporaryurl, response inLet FileManager = Nsfilemanager.defaultmanager ()Let Directoryurl = Filemanager.urlsfordirectory (. Documentdirectory,Indomains:. Userdomainmask) [0]Let pathcomponent
Error message for console printing:Application Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app ' s info.plist file.After the iOS 9 update, Apple swapped the HTTP request for HTTPS and the solution is as follows:true/>Swift--xcode7 sending an HTTP request error using the Alamofire framework
back (if you install the method above)Webhost.createdefaultbuilder (args). UsestartupAlamofire.request ("Http://localhost:5000/api/******/gettables"). Responsejson {response inPrint (Response.request)//original URL requestPrint (Response.response)//HTTP URL responsePrint (Response.data)//data returned by the serverPrint (Response.result)//Response serialization results, in this closure, the JSON data is storedIf let JSON = response.result.value {Print ("JSON: \ (JSON)")}}Use the MacBook to deve
First install Cocoapods
Then open TERMINAL,CD into the folder with the. Xcodeproj.
Enter POD Init
You will create a pod file here
Enter the folder, open pod file (preferably with Xcode), and do the following steps
1. Uncomment Platform:ios, ' 9.0 '
2. Pod ' Alamofire ', ' ~> 3.2.1 ' (if not specified version, will default more than 4.0 version, the build may report many errors)
3. If you have multiple target, add 2 to each target
Then retu
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.